<template>
    <div class="list">
        <div class="table" v-if="active==1">
            <div class="header" style="background-color:white;">
                <el-page-header @back="goBack" content="费用减免申请记录" style="position: relative;top: 10px;left: 5px;">
                </el-page-header>
            </div>
            <el-divider></el-divider>

            <el-form :model="params">
                <el-container>
                    <el-form-item>
                        <el-input v-model="params.content"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-select v-model="params.field" :value="params.field" style="margin-left: 10px">
                            <el-option
                                    :key="type.key"
                                    v-for="type in typeList"
                                    :value="type.key"
                                    :label="type.value"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-select v-model="params.status" :value="params.status" style="margin-left: 10px">
                            <el-option value="" label="审核状态"></el-option>
                            <el-option value="1" label="审核中"></el-option>
                            <el-option value="2" label="审核不通过"></el-option>
                            <el-option value="3" label="审核通过"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item style="margin-left: 10px">
                        <el-button type="primary" @click="handleSearch">检索</el-button>
                    </el-form-item>
                </el-container>
            </el-form>

            <el-table :border="true" :data="pageResult.records">
                <el-table-column prop="id" v-if="false"></el-table-column>
                <el-table-column prop="caseLawId" v-if="false"></el-table-column>
                <el-table-column label="案号" prop="caseNo"></el-table-column>
                <el-table-column label="申请人" prop="person"></el-table-column>
                <el-table-column label="减免金额" prop="decreaseMoney"></el-table-column>
                <el-table-column label="申请日期" prop="applyDate"></el-table-column>
                <el-table-column label="审核状态" prop="status">
                    <template slot-scope="scope">
                        {{scope.row.status=='1'?'审批中':
                        scope.row.status=='2'?'审批不通过':'审批通过'}}
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="text" @click="handleShowDetals(scope.row.caseLawId)">查看</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-footer class="seal-list-footer">
                <el-pagination
                        background
                        layout="prev, pager, next"
                        :total="pageResult.total"
                        :page-size="pageResult.size"
                        class="pagination"
                        @current-change="handleIndexChange"
                >
                </el-pagination>
            </el-footer>
        </div>

        <div class="details" v-if="active==2">
            <feiyong-details
                    @back="back"
                    :law="law"
                    :cwPerformancesplitList="cwPerformancesplitList"
                    :decreaseList="decreaseList">
            </feiyong-details>
        </div>
    </div>
</template>

<script>
    //导入组件
    const FeiyongDetails = () => import('./FeiyongDetails.vue')
    //导入工具类
    import CaseLawService from '../../../model/gs/CaseLawService.js'
    import {CwPerformancesplitService} from "../../../model/ww/cw_performancesplit/CwPerformancesplitService";
    import {CaseDecreaseService} from "../../../model/gs/CaseDecreaseService";
    const caseLawService = CaseLawService.getInstance()
    const cwPerformancesplitService = CwPerformancesplitService.getInstance()
    const caseDecreaseService = CaseDecreaseService.getInstance()

    export default {
        data() {
            return {
                active: 1,
                pageResult:{},
                cwPerformancesplitList:[],
                law:{},
                params:{
                    field:'case_no',
                    status:''
                },
                typeList:[
                    {
                        key:'case_no',
                        value:'案号搜索'
                    },
                    {
                        key:'person',
                        value:'申请人搜索'
                    }
                ],
                decreaseList:[]
            }
        },
        methods:{
            goBack(){
                history.back()
            },
            //子组件返回的方法
            back(){
                this.active = 1
            },
            //获取费用减免数据
            getCaseDecreaseList(){
                caseDecreaseService.getByPage(this.params).then(response => {
                    if(response.data.code === 0){
                        this.pageResult = response.data.data
                    }
                })
            },
            //当前页放生变化的事件
            handleIndexChange(index){
                this.params.page = index
                this.getCaseDecreaseList()
            },
            //检索按钮点击事件
            handleSearch(){
                //重置当前页为1
                this.params.page = 1
                this.getCaseDecreaseList()
            },
            //查看详情的方法
            handleShowDetals(id){
                this.$axios.all([caseLawService.getById(id),
                                caseDecreaseService.getByCaseLaw(id),
                                cwPerformancesplitService.getByCaseLaw(id)])
                    .then(this.$axios.spread((lawResponse,decreaseResponse,cwResponse) => {
                        this.law = lawResponse.data.data
                        this.decreaseList = decreaseResponse.data.data
                        this.cwPerformancesplitList = cwResponse.data.data
                        this.active++
                    }))
            }
        },
        created(){
            this.getCaseDecreaseList()
        },
        components:{
            FeiyongDetails
        }
    }
</script>

<style scoped>
    .list{
        width: 100%;
    }
    .table{
        width: 100%;
    }
    .seal-list-footer{
        margin-top: 20px;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
    }
    .details{
        width: 100%;
    }
</style>